home *** CD-ROM | disk | FTP | other *** search
/ Aminet 28 / Aminet 28 (1998)(GTI - Schatztruhe)[!][Dec 1998].iso / Aminet / dev / c / qtools0.2-src.lha / src / libqdisplay / draw-orig8flat.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-07-13  |  2.0 KB  |  71 lines

  1. #ifdef    USE_ZBUFFER
  2. #define    inc()        { u += du; v += dv; w += dw; }
  3. #define    fill(pel, z) { *zBuffer++ = (unsigned short int)(z); }
  4.  
  5. unsigned short int *draw_affine8flat(int n, unsigned short int *zBuffer, int w, int dw)
  6. {
  7.   while (n--) {
  8.     fill(texture.indexed[multMuls[iv] + iu], w);
  9.     inc();
  10.   }
  11.   return zBuffer;
  12. }
  13. #endif
  14.  
  15. /* given a span (x0,y)..(x1,y), draw a perspective-correct span for it */
  16. /*
  17.  * the zbuffer is interesting for dynamic model-draw etc.
  18.  * the buffers values (1/z) are all under 0, we can try to
  19.  * store them as 16bit-wide-fraction
  20.  *
  21.  * while(n--) {
  22.  *   *zbuf++ = (unsigned short int)(w); / we need only the lower part /
  23.  *   w += dw;
  24.  * }
  25.  *
  26.  */
  27. void draw_spans8flat(int y, int sx, int ex)
  28. {
  29.   unsigned char *pBuffer = (unsigned char *)localDim.frameBuffer + multRows[y] + sx;
  30.   int len = ex - sx, rlen;
  31.  
  32. #ifdef    USE_ZBUFFER
  33.   unsigned short int *zBuffer = localDim.zBuffer + multRows[y] + sx;
  34.   float w0, w1;
  35.   int w, dw;                            /* 1/zbuffer */
  36.   int slen, end;
  37.   float prew = tmap[6] + y * tmap[8];
  38.   float prev = tmap[3] + y * tmap[5];
  39.   float preu = tmap[0] + y * tmap[2];
  40.  
  41.   /* compute (u,v) at left end */
  42.   w0 = 1 / (prew + sx * tmap[7]);                /* 1/zbuffer */
  43.  
  44.   for (slen = len >> SUBDIV_SHIFT; slen > 0; slen--) {
  45.     w = FLOAT_TO_FIX(w0);                    /* 1/zbuffer */
  46.  
  47.     end = sx + SUBDIV;
  48.     w1 = 1 / (prew + end * tmap[7]);
  49.  
  50.     dw = (FLOAT_TO_FIX(v1) - w) >> SUBDIV_SHIFT;        /* 1/zbuffer */
  51.  
  52.     zBuffer = draw_affine8flat(SUBDIV, zBuffer, w, dw);
  53.     sx = end;
  54.  
  55.     w0 = w1;                            /* 1/zbuffer */
  56.   }
  57.  
  58.   w = FLOAT_TO_FIX(w0);                        /* 1/zbuffer */
  59.   if ((rlen = (len & SUBDIV_MASK) - 1)) {            /* a) do not calc if only draw 1 pixel */
  60.     end = sx + rlen;
  61.     w1 = 1 / (prew + end * tmap[7]);
  62.  
  63.     dw = FLOAT_TO_FIX((w1 - w0) / rlen);            /* 1/zbuffer */
  64.   }
  65.   /* a) but draw that pixel surely */
  66.   draw_affine8flat(rlen + 1, zBuffer, w, dw);            /* for the last pixel the du and dv are thrown away */
  67. #endif
  68.   for (rlen = len - 1 - 1; rlen >= 0; rlen--)
  69.     *pBuffer++ = textureColor;
  70. }
  71.